package com.homwork.Collection_learn.List;

import java.util.LinkedList;

public class LinkListCRUD {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        linkedList.add(1);
        linkedList.add(2);
        System.out.println("linkedList="+linkedList);

        linkedList.remove();


        //阅读源码
        /**
         *  1.LinkedList linkedList = new LinkedList();
         *   public LinkedList() {
         *     }
         *  2.这时 linkList 的属性 first =null  last=null
         *  3.执行
         *    public boolean add(E e) {
         *         linkLast(e);
         *         return true;
         *     }
         *   4.将新的结点，加入到双向链表的最后
         *      void linkLast(E e) {
         *         final Node<E> l = last;
         *         final Node<E> newNode = new Node<>(l, e, null);
         *         last = newNode;
         *         if (l == null)
         *             first = newNode;
         *         else
         *             l.next = newNode;
         *         size++;
         *         modCount++;
         *     }
         *

         */
        /**
         * 删除流程的源码
         *  1.去调用removeFirst
         *  public E remove() {
         *         return removeFirst();
         *     }
         *
         *   2.去调用removeFirst
         *   public E removeFirst() {
         *         final Node<E> f = first;
         *         if (f == null)
         *             throw new NoSuchElementException();
         *         return unlinkFirst(f);
         *     }
         *
         *
         * 3.执行unlinkFirst源码 ,将f指向的双向链表的第一结点拿掉
         * private E unlinkFirst(Node<E> f) {
         *         // assert f == first && f != null;
         *         final E element = f.item;
         *         final Node<E> next = f.next;
         *         f.item = null;
         *         f.next = null; // help GC
         *         first = next;
         *         if (next == null)
         *             last = null;
         *         else
         *             next.prev = null;
         *         size--;
         *         modCount++;
         *         return element;
         *     }
         *
         *
         */
    }
}
